package com.xiong.xtools.progressbar;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import com.xiong.xtools.R;

import java.util.Timer;
import java.util.TimerTask;
/**
 * Author : 熊文强
 * Time : 2017/9/19
 * Content : 简约数字进度条
 */
public class PregressBarActivity extends AppCompatActivity implements OnProgressBarListener{

	private Timer timer;
	private NumberProgressBar bnp;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_pregress_bar);

		bnp = (NumberProgressBar)findViewById(R.id.numberbar1);
		bnp.setOnProgressBarListener(this);
		timer = new Timer();
		timer.schedule(new TimerTask() {
			@Override
			public void run() {
				runOnUiThread(new Runnable() {
					@Override
					public void run() {
						bnp.incrementProgressBy(1);
					}
				});
			}
		}, 1000, 100);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		timer.cancel();
	}

	@Override
	public void onProgressChange(int current, int max) {
		if(current == max) {
			Toast.makeText(getApplicationContext(), getString(R.string.finish), Toast.LENGTH_SHORT).show();
			bnp.setProgress(0);
		}
	}
}
